package com.ha.controller.admin;

import com.ha.dto.EmployeePageQueryDTO;
import com.ha.dto.GarbageKindDTO;
import com.ha.dto.GarbageKindPageDTO;
import com.ha.entity.GarbageKind;
import com.ha.mapper.GarbageKindMapper;
import com.ha.result.PageResult;
import com.ha.result.Result;
import com.ha.service.GarbageKindService;
import com.ha.vo.GarbageKindVO;
import com.ha.vo.KindIdVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: GarbageKindController
 * Package: com.ha.controller.admin
 * Description:
 *
 * @Author 那啥啥
 * @Create 2024/4/20  0:00
 * @Version 1.0
 */
@RestController
@RequestMapping("/admin/kind")
@Api(tags = "垃圾分类接口")
@Slf4j
public class GarbageKindController {
    @Autowired
    private GarbageKindService garbageKindService;
    /**
     * 添加垃圾种类
     * @param garbageKindDTO
     * @return
     */
    @PostMapping
    @ApiOperation("添加垃圾种类")
    public Result addKind(@RequestBody GarbageKindDTO garbageKindDTO){

        garbageKindService.addKind(garbageKindDTO);
        return Result.success();
    }


    /**
     * 垃圾种类分页查询
     * @param garbageKindPageDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("员工分页查询")
    public Result<PageResult> page(GarbageKindPageDTO garbageKindPageDTO){
        log.info("垃圾种类分页查询参数为 ：{}",garbageKindPageDTO);
        PageResult pageResult = garbageKindService.pageQuery(garbageKindPageDTO);
        return Result.success(pageResult);
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation("根据id删除垃圾种类")
    public Result delete(@PathVariable Long id){
        garbageKindService.deleteById(id);
        return Result.success();
    }

    /**
     * 更新
     * @param garbageKindDTO
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("更新接口")
    public Result update(@RequestBody  GarbageKindDTO  garbageKindDTO){
        garbageKindService.update(garbageKindDTO);
        return Result.success();
    }

    /**
     * 根据id回显数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id回显数据")
    public Result<GarbageKind> getById(@PathVariable Long id){
        GarbageKind garbageKind = garbageKindService.getById(id);
        return Result.success(garbageKind);
    }

    /**
     * 回显id种类
     * @return
     */
    @GetMapping("/kindID")
    @ApiOperation("回显id种类")
    public Result<List<KindIdVO>> getKind(){
        List<KindIdVO> list = garbageKindService.getKindVOList();
        return Result.success(list);
    }
}
